package com.acwing.partition20;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/1/16 19:31
 */
public class AC1945奶牛棒球_双指针 {

    private static final int N = 1010;
    private static int[] nums = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(reader.readLine());
        writer.write(resolve() + "\n");
        writer.flush();
    }

    private static int resolve() {
        int answer = 0;
        Arrays.sort(nums, 0, n);
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1, left = j + 1, right = j + 1; j < n - 1; j++) {
                while (left < n && nums[left] - nums[j] < nums[j] - nums[i]) left++;
                while (right < n && nums[right] - nums[j] <= 2 * (nums[j] - nums[i])) right++;
                answer += right - left;
            }
        }
        return answer;
    }
}
